package main

import (
	"fmt"
	"html/template"
	"os"
)

type Friend struct{
	Fname string
}

type Person struct{
	UserName string
	Emails []string
	Friends []*Friend
}

func main(){
	fmt.Println("example1...")
	f1:=Friend{"miunx.ma"}
	f2:=Friend{"xushiwei"}
	t:=template.New("fieldname example")
	t,_=t.Parse(`hello {{.UserName}}
	{{range .Emails}}
		an email {{.}}
	{{end}}
	{{with .Friends}}
	{{range .}}
		my friend name is {{.Fname}}
	{{end}}
	{{end}}
	`)
	p:=Person{UserName:"shawn",
		Emails:[]string{"shawnplays@sina.com","zhaoxp2@lenovo.com"},
		Friends:[]*Friend{&f1,&f2},
	}
	t.Execute(os.Stdout,p)
}
